﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum Flower { fangKuai, meiHua, hongTao, heiTao }
public enum Point { s2, s3, s4, s5, s6, s7, s8, s9, s10, J, Q, K, A }

public class Card
{
    public readonly Flower flower;
    public readonly Point point;

    public Card(Flower f, Point p)
    {
        flower = f;
        point = p;
    }

    public override string ToString()
    {
        string point;
        switch (this.point)
        {
            case Point.s2:
                point = "2"; break;
            case Point.s3:
                point = "3"; break;
            case Point.s4:
                point = "4"; break;
            case Point.s5:
                point = "5"; break;
            case Point.s6:
                point = "6"; break;
            case Point.s7:
                point = "7"; break;
            case Point.s8:
                point = "8"; break;
            case Point.s9:
                point = "9"; break;
            case Point.s10:
                point = "X"; break;
            case Point.J:
                point = "J"; break;
            case Point.Q:
                point = "Q"; break;
            case Point.K:
                point = "K"; break;
            case Point.A:
                point = "A"; break;
            default:
                point = "*"; break;
        }
        switch (flower)
        {
            case Flower.fangKuai:
                return "<color=\"red\">♦" + point + "</color> ";
            case Flower.meiHua:
                return "<color=\"blue\">♣" + point + "</color> ";
            case Flower.hongTao:
                return "<color=\"red\">♥" + point + "</color> ";
            case Flower.heiTao:
                return "<color=\"blue\">♠" + point + "</color> ";
            default: return "*" + point;
        }
    }

    public override bool Equals(object obj)
    {
        return obj is Card card &&
               flower == card.flower &&
               point == card.point;
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(flower, point);
    }

    public static bool operator >(Card c1, Card c2)
    {
        if (c1.point != c2.point) return c1.point > c2.point;
        else return c1.flower > c2.flower;
    }

    public static bool operator <(Card c1, Card c2)
    {
        if (c1.point != c2.point) return c1.point < c2.point;
        else return c1.flower < c2.flower;
    }

    public static bool operator ==(Card c1, Card c2)
        => c1.point == c2.point;

    public static bool operator !=(Card c1, Card c2)
        => c1.point != c2.point;

}

